package com.example.demo.MyStack.string;

import java.util.Stack;

public class fuhaoApp {
    public static void main(String[] args) {
        String str = "{[())]}";
        Stack stack = new Stack();
        for (int i = 0; i < str.length(); i++) {
            char cha = str.charAt(i);
            switch (cha) {
                case '{':
                    stack.push(cha);
                    break;
                case '[':
                    stack.push(cha);
                    break;
                case '(':
                    stack.push(cha);
                    break;
                case ')': {
                    String string = stack.pop().toString();
                    if (!string.equals("(")) {
                        throw new RuntimeException("报错了，靓仔  符号有问题:"+i);
                    }
                    break;
                }
                case '}': {
                    String string = stack.pop().toString();
                    if (!string.equals("{")) {
                        throw new RuntimeException("报错了，靓仔  符号有问题:"+i);
                    }
                    break;
                }
                case ']': {
                    String string = stack.pop().toString();
                    if (!string.equals("[")) {
                        throw new RuntimeException("报错了，靓仔  符号有问题:"+i);
                    }
                    break;
                }
            }
        }
        System.out.println("无符号异常");
    }
}
